package net.ikenway.springboot.demo.Model.Entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.*;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;

/**
 * @author MasterKenway <zk@ikenway.net>
 * @Description
 * @date Created Date 12/9/2020
 */
@Entity
@DynamicUpdate
@Data
@Table(name = "products")
@NoArgsConstructor
@AllArgsConstructor
public class Product implements Serializable {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "product_id")
    private Long productId;

    @Column(unique = true)
    private String productName;
    private String preview;

    @ManyToOne(targetEntity = ProductSort.class, fetch = FetchType.LAZY, cascade = CascadeType.DETACH)
    @JoinColumn(name = "sort_id")
    private ProductSort productSort;

    private BigDecimal mediumPrice;
    private BigDecimal largePrice;

    private BigDecimal disCount = new BigDecimal(1);

    @Column(nullable = false)
    private Integer sellCounter = 0;

    private Boolean deleted = false;

    @ManyToMany(targetEntity = Activity.class, cascade = CascadeType.PERSIST, fetch = FetchType.LAZY)
    private List<Activity> activities;
}

